using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;
namespace BUS
{
   public class tbDonhangBUS
    {
        public static int Insert(tbDonhang dh)
        {
            tbDonhangDAL dhDAL = new tbDonhangDAL();
           return dhDAL.Insert(dh);
        }
        public static void Update(tbDonhang dh)
        {
            tbDonhangDAL dhDAL = new tbDonhangDAL();
            dhDAL.Update(dh);
        }
        public static void Delete(int iD)
        {
            tbDonhangDAL dhDAL = new tbDonhangDAL();
            dhDAL.Delete(iD);
        }
        public static tbDonhangCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbDonhangDAL dhDAL = new tbDonhangDAL();
            return dhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbDonhangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDonhangDAL dhDAL = new tbDonhangDAL();
            return dhDAL.Get(cri.Criter, 0, 0, tbDonhangColumn.Madh.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbDonhang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbDonhangColumn.Madh.ToString(), Condition.EQUAL, iD);
            tbDonhangDAL dhDAL = new tbDonhangDAL();
            tbDonhangCollection dhCollection = dhDAL.Get(cri.Criter, 0, 0, tbDonhangColumn.Madh.ToString(), OrderDirection.ASC.ToString(), out total);
            if (dhCollection.Count > 0)
                return dhCollection[0];
            return null;
        }
        public static tbDonhangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDonhangDAL dhDAL = new tbDonhangDAL();
            return dhDAL.Get(cri.Criter, 1, number,
            tbDonhangColumn.Madh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbDonhangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDonhangDAL dhDAL = new tbDonhangDAL();
            return dhDAL.Get(cri.Criter, 1, number,
            tbDonhangColumn.Madh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
